import { defineConfig, loadEnv, ConfigEnv, UserConfig } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import eslintPlugin from 'vite-plugin-eslint'
import WindiCSS from 'vite-plugin-windicss'

// https://vitejs.dev/config/
// export default defineConfig({
//   plugins: [vue()],
// })

export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
	const env = loadEnv(mode, process.cwd())
	console.log(env)
  return {
    base: './',
    resolve: {
		alias: {
			'@': resolve(__dirname, './src'),
			// 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
		}
	},
	css: {
		preprocessorOptions: {
			scss: {
				additionalData: `@import "@/styles/var.scss";`
			}
		}
	},
    server: {
		// 服务器主机名，如果允许外部访问，可设置为 '0.0.0.0'
		host: '0.0.0.0',
		port: 8898,
		open: false,
		cors: true,
		// 跨域代理配置
		proxy: {
			'/api': {
				// target: 'https://mock.mengxuegu.com/mock/64350d8856377f1ed96c0999',
				// target: 'http://test.api.qianhoukeji.com:80/',
				// target: 'https://mock.mengxuegu.com/mock/629d727e6163854a32e8307e', // easymock
				// target: 'https://www.fastmock.site/mock/f81e8333c1a9276214bcdbc170d9e0a0', // fastmock
				target: 'http://10.200.52.250:5299',
				// http://10.200.52.250:5299/api/EPC/GetVinInfoByVinNumber?_vinCode=1FM5K8F83DGC88195
				changeOrigin: true,
				rewrite: path => path.replace(/^\/api/, '')
			},
			'/v1api': {
				target: 'https://mock.mengxuegu.com/mock/64350d8856377f1ed96c0999',
				changeOrigin: true,
				rewrite: path => path.replace(/^\/v1api/, '')
			}
		}
	},
    plugins: [
      vue(),
      eslintPlugin(),
	  WindiCSS()
    ]
  }
})
